<template>
  <view class="w-full max-w-[750rpx] mx-auto min-h-screen bg-[#f6f8fa] p-[32rpx] box-border">
    <text class="block text-[48rpx] font-extrabold mb-[40rpx] text-center text-blue-600 drop-shadow">新增社会经济学信息</text>
    <FormView :fieldConfig="fieldConfig" :form="form" :showButtons="true" @submit="submitForm" />
  </view>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import Taro from '@tarojs/taro'
import { healthSocialInfoFields as fieldConfig } from './fields'
import FormView from '@/components/FormView.vue'
import { request } from '@/service/request'

onMounted(async () => {
  const dicts = await request.get<any>('/health_records/health_social/healthSocialInfo/list', {}, {
    useErrMsg: true
  })
  console.log(dicts)
})

const form = reactive<any>({})

async function submitForm(form: any, fieldConfig: any) {
  // 校验和保存逻辑
  Taro.showToast({ title: '保存成功', icon: 'success' })
  console.log(form)
  const params = {
    ...form,
    mediDebt: form.mediDebt ? 1 : 0,
  }
  const dicts = await request.post<any>('/health_records/health_social/healthSocialInfo/add', params, {
    useErrMsg: true
  })
  console.log(dicts)
}

</script>
